package ru.cod.rs.main.units.parts;

import ru.cod.rs.R;
import ru.cod.rs.main.units.AbstractUnit;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.view.SurfaceView;

public abstract class AbstractPart extends AbstractUnit {

	protected Bitmap image;

	// /////////////////////////////////////////////////////////

	public AbstractPart(SurfaceView cntx, int abc, int ord) {
		super(cntx, abc, ord);
		setImage();
	}

	public AbstractPart(SurfaceView cntx) {
		super(cntx);
		setImage();
	}

	// /////////////////////////////////////////////////////////

	/*
	 * @see ru.cod.rs.main.units.AbstractUnit#render(android.graphics.Canvas)
	 */
	@Override
	public void render(Canvas canvas) {
		canvas.drawBitmap(image, x, y, null);
	}

	// ////////////////////////////////////////////////////////

	/**
	 * @return the image
	 */
	public Bitmap getImage() {
		return (image != null) ? image : getBitmap(R.drawable.bp_1);
	}

	/**
	 * @param image
	 *            the image to set
	 */
	public void setImage(Bitmap image) {
		if (image != null) {
			this.image = image;
		} else {
			this.image = getBitmap(R.drawable.bp_1);
		}

	}

	/*
	 * 
	 */
	@Override
	public int getWidth() {
		return (image != null) ? image.getWidth() : super.getWidth();
	}

	/*
	 * 
	 */
	@Override
	public int getHeight() {

		return (image != null) ? image.getHeight() : super.getHeight();
	}

	protected void setImage() {
		image = getBitmap(R.drawable.bp_1);
	}

}
